#include <avr/io.h>
#include "spi.h"

#define DD_MOSI    PINB3
#define DD_SCK     PINB5
#define DDR_SPI    PORTB

//copied from atmega16 datascheet
void SPIInit()
{
 /* Set MOSI and SCK output, all others input */
 DDR_SPI = (1<<DD_MOSI) | (1<<DD_SCK);
 /* Enable SPI, master, set clock rate fck/16 */
 SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR0);
}
/* Sending and receiving data from the spi bus */
unsigned char SPITransmit(unsigned char data)
{
 /* Start transmission */
 SPDR = data;
 /* Wait for transmission complete */
 while(!(SPSR & (1<<SPIF)))
  ;
 return SPDR;
}


